/**
 *
 */
package com.itee.core.util;

import javafx.application.Platform;
import javafx.scene.control.TextArea;

import java.io.OutputStream;
import java.io.PrintStream;

/**
 * @author moxin
 */
public class GuiPrintStream extends PrintStream {

    private TextArea mTextArea;

    public GuiPrintStream(OutputStream out, TextArea textArea, boolean autoFlush) {
        super(out, autoFlush);
        mTextArea = textArea;
    }

    @Override
    public void print(String s) {
        updateTextArea(s);
    }

    @Override
    public void println(String x) {
        updateTextArea(x);
    }

    private void updateTextArea(final String text) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                mTextArea.appendText(text + "\n");
            }
        });
    }

}
